﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SchoolYearMonth.ascx.cs" Inherits="Custom_SchoolYearMonth" %>
<script type="text/javascript">
    var schoolYearTerm = new  Array();
    var SchoolYearMonths = new Array();
    //当前选中学年
    var GetCurrentSchoolYear = 0;
    //当前选中学期
    var GetCurrentSchoolTerm = 0;
    //当前选中年
    var GetCurrentYear=0;
    //当前选中月
    var GetCurrentMonth=0;
    var OnChange=null;
    //设置回调
    function SetChange(obj)
    {
        OnChange = obj;
    }
    function startChange()
    {
        GetCurrentSchoolYear=event.srcElement.options[event.srcElement.selectedIndex].SchoolYear;
        GetCurrentSchoolTerm = event.srcElement.options[event.srcElement.selectedIndex].Term;

        InitMonth(GetCurrentSchoolYear,GetCurrentSchoolTerm);
        if(OnChange!=null)
        {
            OnChange(GetCurrentSchoolYear,GetCurrentSchoolTerm);
        }
    }
    function monthChange()
    {
        GetCurrentYear = event.srcElement.options[event.srcElement.selectedIndex].year;
        GetCurrentMonth = event.srcElement.options[event.srcElement.selectedIndex].month;
    }
    function InitMonth(year,term)
    {
        for(var i=0;i<SchoolYearMonths.length;i++)
        {
            if(SchoolYearMonths[i].SchoolYear==year && SchoolYearMonths[i].Term==term)
            {
                var sel = document.getElementById("month");
                sel.innerHTML="";
                for(var j=0;j<SchoolYearMonths[i].Months.length;j++)
                {
                    var oOption = document.createElement("OPTION");
                    oOption.text = SchoolYearMonths[i].Months[j].year+"年"+SchoolYearMonths[i].Months[j].month+"月";
                    oOption.year = SchoolYearMonths[i].Months[j].year;
                    oOption.month = SchoolYearMonths[i].Months[j].month;
                    if(j == 0)
                    {
                        GetCurrentYear = SchoolYearMonths[i].Months[j].year;
                        GetCurrentMonth = SchoolYearMonths[i].Months[j].month;
                        oOption.selected = true;
                    }
                    else
                    {
                        oOption.selected = false;
                    }
                    sel.add(oOption);
                }
            }
        }
    }
    function InitSelect(selectId,year,term)
    {
        GetCurrentSchoolTerm = term;
        GetCurrentSchoolYear = year;
        var sel = document.getElementById(selectId);
        if(sel!=null)
        {

            for(i=0;i<schoolYearTerm.length;i++)
            {

                var oOption = document.createElement("OPTION");
                oOption.text = schoolYearTerm[i].Name;
                oOption.SchoolYear = schoolYearTerm[i].SchoolYear;
                oOption.Term = schoolYearTerm[i].Term;
                if(year == i)
                {
                    oOption.selected = true;
                }
                else
                {
                    oOption.selected = false;
                }
                sel.add(oOption);
            }
        }
        InitMonth(year,term)
    }
</script>
学期：<select id="startYear" onchange="startChange()"></select> 年月：<select id="month" onchange="monthChange()"></select>
            
<script language="javascript">
 <%
        int index =0;
        foreach(Meqs.Entity.TermInfo y in terms)
        {
            Response.Write("schoolYearTerm["+index+"]={SchoolYear:"+y.SchoolYear+",Term:"+y.Term+",Name:'"+Common.ConvertYearAndTerm(y.SchoolYear,y.Term)+"'};");
            index++;
        }
        index=0;
        foreach(YearMonthList y in yearmonthlist)
        {
            Response.Write("SchoolYearMonths["+index+"]={SchoolYear:"+y.schoolyear+",Term:"+y.term+"};");
            Response.Write("SchoolYearMonths["+index+"].Months=new Array();");
            int mindex = 0;
            foreach(YearAndMonth ym in y.months)
            {
                
                 Response.Write("SchoolYearMonths["+index+"].Months["+mindex+"]={year:"+ym.year+",month:"+ym.month+"};");
                 mindex++;
            }
            index++;
        }
        if(terms.Count>0)
        {
            Response.Write("InitSelect('startYear',"+terms[0].SchoolYear+","+terms[0].Term+");");
        }
        
 %>
 </script>